package com.company.returnsion;

import java.util.Map;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}15:30
 */
public class Queue {
//    int max = 4;

    static int count = 0;
    static int judgeCount = 0;

    public static void main(String[] args) {
        Queue queue = new Queue();
        queue.useMax(8);
    }

    public  boolean judge(int n,int[] arr){
        for (int i = 0; i < n;i++){
            if (arr[n] == arr[i]||Math.abs(n-i) == Math.abs(arr[n]-arr[i])){
                return false;
            }
        }
        return true;
    }
    public void useMax(int max){
        int arr[] = new int[max];
        check(0,max,arr);
    }
    public  void check(int n,int max,int[] arr){
        if (n == max){
            print(arr);
           return;
        }
        //依次放入皇后
        for (int i = 0; i < max;i++){
            //将第n个皇后依次放入第i个格子
            arr[n] = i;
            if (judge(n,arr)){
                check(n+1,max,arr);//每次递归就是新的一行
            }
        }
    }

    public void print(int[] arr){
        for (int i = 0; i < arr.length; i++){
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
    }

}
